-
Notifications
You must be signed in to change notification settings - Fork 10
Return empty modules array when module command is not available #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For PHP-CS-Fixer errors, the command make fix-code
can be run to auto-fix them
if (strpos($exception->getMessage(), 'unknown command') === false) { | ||
throw $exception; | ||
} | ||
$modules = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can return null
directly, because the foreach
will have nothing to run
$modules = []; | |
return null; |
try { | ||
$modules = $client->executeRaw('module', 'list') ?? []; | ||
} catch (\Throwable $exception) { | ||
if (strpos($exception->getMessage(), 'unknown command') === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yoda style test is used (see PHP-CS-Fixer error: https://github.com/MacFJA/php-redisearch/runs/7054519075?check_suite_focus=true)
if (strpos($exception->getMessage(), 'unknown command') === false) { | |
if (false === strpos($exception->getMessage(), 'unknown command')) { |
$modules = $client->executeRaw('module', 'list') ?? []; | ||
try { | ||
$modules = $client->executeRaw('module', 'list') ?? []; | ||
} catch (\Throwable $exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\Throwable
should be imported (see PHP-CS-Fixer error: https://github.com/MacFJA/php-redisearch/runs/7054519075?check_suite_focus=true)
Closing in favor of #53 |
When connecting to a Redis server with limited rights the module command may not be available. Predis throws an exception and executing commands is not possible. This happend with Redis Enterprise Cloud server where Redisearch is available but the module command not.